package com.hxk.security.dao;

import com.hxk.security.bean.User;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Repository
public class UserRepository {

    public User findOneByLogin(String userName){
        List<User> list = new ArrayList<>();
        PasswordEncoder passwordEncoder =new BCryptPasswordEncoder();
        list.add(new User(1L,"hxk",passwordEncoder.encode("123456"), Arrays.asList("VIP1")));
        list.add(new User(1L,"root",passwordEncoder.encode("123456"),Arrays.asList("VIP2","VIP3")));
        list.add(new User(1L,"admin",passwordEncoder.encode("123456"),Arrays.asList("VIP1","VIP2","VIP3")));
        return list.stream().filter(u->{return u.getUserName().equals(userName);}).collect(Collectors.toList()).get(0);
    }
}
